<?php
namespace app\index\controller;

use think\Controller;
use app\index\model\Gltorder as gltorderModel;
use function think\select;

class Gltorder extends Controller {
	
	// 预约
	public function order() {
		$gltorder_id = input('post.id');
		$gltorder_name = input('post.name');
		$gltorder_ordertime = input('post.ordertime');
		$gltorder_identify = input('post.identify');
		$gltorder_phone = input('post.phone');
		$gltorder_area = input('post.area');
		$gltorder_vehicle = input('post.vehicle');
		
		$gltorder = new Gltorder();
		//进行规则验证
		$result = $this->validate(
				[
						'姓名' => $gltorder_name,
						'预约时间' => $gltorder_ordertime,
						'身份证' => $gltorder_identify,
						'手机号码' => $gltorder_phone,
						'客源地' => $gltorder_area,
						'交通方式' => $gltorder_vehicle,
				], 
				[
						'姓名' => 'require',
						'预约时间' => 'require',
						'身份证' => 'require',
						'手机号码' => 'require',
						'客源地' => 'require',
						'交通方式' => 'require',
				]);
		if(true !== $result) {
			$this->error($result);
		} else {
			$gltorder->name = $gltorder_name;
			$gltorder->identify = $gltorder_identify;
			$gltorder->phone = $gltorder_phone;
			$gltorder->area = $gltorder_area;
			$gltorder->vehicle = $gltorder_vehicle;
			$gltorder->ordertime = $gltorder_ordertime;
			
			$gltorder = GltorderModel::create($gltorder);
		}
		
		$list = gltorderModel::scope(function($query){
			$query->where('phone', input('post.phone'))->order('id desc');
		})->select();
		
		$this -> view -> assign('list', $list);
		$this -> view -> assign('phone', input('post.phone'));
		return $this->view->fetch('ordersuccess');
		
	}
	
	/**
	 * 注册（伪）
	 */
	public function regist() {
		$list = gltorderModel::scope(function($query){
			$query->where('phone', input('post.phone'))->order('id desc');
		})->select();
		$this -> view -> assign('list', $list);
		$this -> view -> assign('phone', input('post.phone'));
		return $this->view->fetch('index');
	}
	
	/*
	 * 预约成功页跳转记录
	 */
	public function record() {
		$list = gltorderModel::scope(function($query){
			$query->where('phone', input('post.phone'))->order('id desc');
		})->select();
		$this -> view -> assign('list', $list);
		$this -> view -> assign('phone', input('post.phone'));
		return $this->view->fetch('index');
	}
	
	
	
	
	
	
	
	
	
	
	
}